/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.com.wholeconsulting.pacc.persistance.database;

import ar.com.wholeconsulting.pacc.model.Direccion;
import ar.com.wholeconsulting.pacc.model.Fluido;
import ar.com.wholeconsulting.pacc.model.Usuario;
import ar.com.wholeconsulting.pacc.persistance.JPASession;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Duco Pablo
 */
public class UsuarioImporter extends Importer {
    
    private static final String QUERY = "select * from empresas";

    public UsuarioImporter(Connection con) {
        super(con);
    }

    @Override
    protected void importData(ResultSet rs) {
        Usuario usr = new Usuario();
        try {
            usr.setNombre(rs.getString(2));
            usr.setPlanta(rs.getString(3));
            usr.setRubro(rs.getString(4));
            usr.setExpediente(rs.getString(7));
            usr.setCuit(rs.getString(8));
            Direccion dir = new Direccion();
            dir.setCalle(rs.getString(9));
            dir.setNumero(rs.getString(10));
            dir.setPiso(rs.getString(11));
            dir.setOficina(rs.getString(12));
            dir.setLocalidad(rs.getString(13));
            dir.setCodigoPostal(rs.getString(14));
            dir.setPartido(rs.getString(15));
            dir.setProvincia(rs.getString(16));
            usr.setDireccion(dir);
            usr.setTelefono(rs.getString(17));
            usr.setEmail(rs.getString(19));
            JPASession.getInstance().getManager().persist(usr);
        } catch (SQLException ex) {
            Logger.getLogger(FluidoImporter.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void importaData() {
        try {
            queryData(QUERY);
        } catch (SQLException ex) {
            Logger.getLogger(FluidoImporter.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
